import { request } from "../../request/index.js"
import regeneratorRuntime from "../../lib/runtime/runtime"

// pages/page_new/page_new.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    chooseList: [],
    tempFilePaths: [],
    location: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },


  addImage() {
    wx.chooseImage({
      count: (9 - this.data.chooseList.length),
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: (result) => {
        const tempFilePaths = result.tempFilePaths
        this.data.tempFilePaths.push(...tempFilePaths)
        this.setData({
          chooseList: this.data.tempFilePaths
        })
      },
      fail: () => {},
      complete: () => {}
    })
  },

  delImage(e) {
    let chooseList = this.data.chooseList
    chooseList.splice(e.currentTarget.dataset.id, 1)
    this.setData({
      chooseList
    })
  },

  address() {
    wx.chooseLocation({
      success: (result) => {
        const location = result
        this.setData({
          location
        })
      }
    })
  }
})